<template>
	<div class="kp-trainlist train">
		<header class="kp-header">
			<div class="kp-heatop">
				<span class="train_i" @click="clickReturn"></span>
				<div class="kp-headtrain tc">
					<p class="trainlist_city">{{cityMsg.fromCity}}-{{cityMsg.toCity}}</p>
					<p class="trainlist_num">共{{sortList.length}}趟列车</p>
				</div>
				<span class="train_fan" @click="changeTrain(true)" v-if="!isChangTicket">返程查询</span>
			</div>
			<div class="kp-headerday">
				<span class="kp-new" :class="{'kp-old' : departureDateMsg.isToday}" @click="preday">前一天</span>
				<div class="kp-message">
					<router-link :to="'/train/date?departureDate=' + departureDate + '&isChangTicket=' + Number(isChangTicket)">
						<div class="kp-messdate">
							<span class="kp-traintime">
								<em>{{departureDateMsg.day}}</em>
								<em v-if="departureDateMsg.isToday">今天</em>
								<em v-else-if="departureDateMsg.isTomorrow">明天</em>
								<em v-else>{{departureDateMsg.week}}</em>
							</span>
							<span class="kp-trainicon"></span>
						</div>
					</router-link>
				</div>
				<span class="kp-new" :class="{'kp-old' : endDate == departureDate}" @click="nextday">后一天</span>
			</div>
		</header>
		<div class="kp-traincont">
			<div class="trainlist_student_tip">
				学生票可售日期为：6月1日-9月30日，12月1日-3月31日，且只支持硬座/硬卧/二等座/无座，实际价格以占座成功后票价为准
			</div>
			<div class="trainlist">
				<div class="trainitem mb20" v-for="item,index in trainList" v-if="sortList.length" @click="trainDetails(item)">
					<!--车次信息-->
					<div class="trainitem_top wccy-after">
						<div>
							<div class="trainitem_start tc">
								<p class="train_city">{{item.fromStation}}</p>
								<p class="train_time train_Startime">{{item.fromTime}}</p>
							</div>
							<div class="trainitem_icon tc">
								<p class="train_hao">{{item.trainNo}}<span class="train_haoem" v-if="item.pullInByIdCard" @click.stop="isByIdCard = true;" ></span></p>
								<p class="train_icont"></p>
								<p class="train_shiji">{{item.runTimeSpan | runTime}}</p>
							</div>
							<div class="trainitem_end tc">
								<p class="train_city">{{item.toStation}}</p>
								<p class="train_time">{{item.toTime}}</p>
							</div>
						</div>
						<div class="trainitem_price tr fr">
							<p class="trainprice"><span class="trainspan"><em class="train_yj">￥</em>{{item.smalePrice}}<em class="train_hz">起</em></span></p>
							<p class="price_fan" v-if="HCCashBackFlag" v-show="item.smalePrice > 3.6"><span class="price_fanpr">返<em class="train_prifan">￥</em>{{item.smalePrice | returnMoney}}</span></p>
						</div>
					</div>
					<!--余票信息-->
					<div class="trainitem_bot" v-if="item.showNone">
						<ul class="wccy-after trainitem_ul">
							<li v-for="val,key in item.ticketsArr">
								<div :class='{"train_none" : item.seats>0}' class="gray">{{val.seatName}}
									<span v-if="val.seats>20">有</span>
									<span v-else>{{val.seats}}</span>
									<span class='train_em' v-show='item.seats<0'>(抢)</span>
								</div>
							</li>
						</ul>
					</div>
					<div class="trainitem_bot" v-else>
						<div v-if="(item.saleFlag == '2' || item.saleFlag == '3') && advanceDate.trainQPvanceDays" class='train_presell'>
							<span>该车次{{item.note}},可预约抢票</span>
							<span class='train_presell_btn'>预约抢票</span>
						</div>
						<div class="train_pno" v-else>
							<span>暂无余票，建议抢票</span>
							<!--抢票标签-->
							<img src="../../../assets/train/keqiangpiao@2x.png" alt="" class="train_rob_pic"/>
						</div>
					</div>
				</div>
				<div class="trainitem_null" v-show="!sortList.length" v-if="isNullShow">
					<img src="../../../assets/train/noresult.png" alt="" />
				</div>
			</div>
			<div class="train_f"></div>
			<div class="train_footer">
				<ul class="wccy-after">
					<li class="waccy-li" :class="{active:chose==0}" @click="filtRate">
						<p class="train_ficon"><span class="train_shai"></span></p>
						<p class="train_fzi">筛选</p>
					</li>
					<li class="waccy-li" :class="{active:chose==1}" @click="depart">
						<p class="train_ficon"><span class="train_chuf"></span></p>
						<p class="train_fzi" v-if="chose!=1">出发</p>
						<p class="train_fzi" v-else-if="departFlag">出发从晚到早</p>
						<p class="train_fzi" v-else>出发从早到晚</p>
					</li>
					<li class="waccy-li" :class="{active:chose==2}" @click="costTime">
						<p class="train_ficon"><span class="train_haos"></span></p>
						<p class="train_fzi" v-if="chose!=2">耗时</p>
						<p class="train_fzi" v-else-if="costTimeFlag">耗时 长到短</p>
						<p class="train_fzi" v-else>耗时 短到长</p>
					</li>
					<li class="waccy-li" :class="{active:chose==3}" @click="have">
						<p class="train_ficon"><span class="train_you"></span></p>
						<p class="train_fzi">有票优先</p>
					</li>
				</ul>
			</div>
		</div>
		<div class="kp-trainshai" v-show="maskShowFlag">
			<div class="kp-traindiv">
				<div class="train_che">
					<div class="train_btn">
						<span class="train_qux" @click="maskClick">取消</span>
						<span class="train_qud" @click="submit">确定</span>
					</div>
					<div class="train_div">
						<div class="train_top tc">
							<span class="train_choose">车型选择</span>
						</div>
						<div class="train_timechose">
							<ul class="wccy-after">
								<li class="train_itemcar" @click="filtRateClick(4,'car')" :class="{'active':filtrate.arr[4]}"><span class="train_hanzi">不限</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(0,'car')" :class="{'active':filtrate.arr[0]}"><span class="train_hanzi">高铁(G/C)</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(1,'car')" :class="{'active':filtrate.arr[1]}"><span class="train_hanzi">动车(D)</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(2,'car')" :class="{'active':filtrate.arr[2]}"><span class="train_hanzi">普通(Z/T/K)</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(3,'car')" :class="{'active':filtrate.arr[3]}"><span class="train_hanzi">其他(L/Y等)</span><em class="train_itemem"></em></li>
							</ul>
						</div>
					</div>
					<div class="train_div">
						<div class="train_top tc">
							<span class="train_choose">出发时间</span>
						</div>
						<div class="train_timechose">
							<ul class="wccy-after">
								<li class="train_itemcar" @click="filtRateClick(4,'fromTime')" :class="{'active':filtrate.setOut[4]}"><span class="train_hanzi">不限</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(0,'fromTime')" :class="{'active':filtrate.setOut[0]}"><span class="train_hanzi">00:00-06:00</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(1,'fromTime')" :class="{'active':filtrate.setOut[1]}"><span class="train_hanzi">06:00-12:00</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(2,'fromTime')" :class="{'active':filtrate.setOut[2]}"><span class="train_hanzi">12:00-18:00</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(3,'fromTime')" :class="{'active':filtrate.setOut[3]}"><span class="train_hanzi">18:00-24:00</span><em class="train_itemem"></em></li>
							</ul>
						</div>
					</div>
					<div class="train_div">
						<div class="train_top tc">
							<span class="train_choose">到达时间</span>
						</div>
						<div class="train_timechose">
							<ul class="wccy-after">
								<li class="train_itemcar" @click="filtRateClick(4,'toTime')" :class="{'active':filtrate.arrive[4]}"><span class="train_hanzi">不限</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(0,'toTime')" :class="{'active':filtrate.arrive[0]}"><span class="train_hanzi">00:00-06:00</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(1,'toTime')" :class="{'active':filtrate.arrive[1]}"><span class="train_hanzi">06:00-12:00</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(2,'toTime')" :class="{'active':filtrate.arrive[2]}"><span class="train_hanzi">12:00-18:00</span><em class="train_itemem"></em></li>
								<li class="train_itemcar" @click="filtRateClick(3,'toTime')" :class="{'active':filtrate.arrive[3]}"><span class="train_hanzi">18:00-24:00</span><em class="train_itemem"></em></li>
							</ul>
						</div>
					</div>
				</div>
				<div class="train_close">
					<div @click="maskClick" >
						<img src="../../../assets/train/guanbi@2x.png" alt=""/>		
					</div>
				</div>
			</div>
		</div>
		<byIdCard @mask='idCardClick' v-show="isByIdCard"></byIdCard>
		<kpmask @mask='maskClick' v-show="maskShowFlag"></kpmask>
	</div>
</template>
<style scoped>
	* {
		box-sizing: border-box;
	}
	
	.mb20 {
		margin-bottom: 20px;
	}
	
	.kp-trainlist {
		background: #f4f5f9;
		min-height: 100vh;
		font-family: "MicrosoftYaHei";
		letter-spacing: 0;
	}
	
	.kp-header {
		width: 100%;
		height: 185px;
		position: fixed;
		background: #fff;
		left: 0;
		top: 0;
		z-index: 250;
	}
	
	.kp-heatop {
		position: relative;
		width: 100%;
		height: 96px;
		border-bottom: 2px solid rgb(233, 233, 233);
		padding-top: 23px;
	}
	
	.kp-headtrain {
		width: 100%;
	}
	
	.trainlist_city {
		color: rgb(51, 51, 51);
		font-size: 32px;
	}
	
	.trainlist_num {
		color: rgb(138, 138, 138);
		font-size: 24px;
		margin-top: 10px;
	}
	
	.train_i {
		display: inline-block;
		width: 25px;
		height: 44px;
		background: url("../../../assets/left-2.png") center no-repeat;
		background-size: 25px 44px;
		position: absolute;
		left: 30px;
		top: 50%;
		margin-top: -22px;
	}
	
	.train_fan {
		color: rgb(59, 195, 194);
		font-size: 28px;
		position: absolute;
		right: 31px;
		top: 40px;
	}
	
	.kp-headerday {
		padding: 0 30px;
		line-height: 88px;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.kp-new {
		color: rgb(59, 195, 194);
		font-size: 26px;
		display: inline-block;
	}
	
	.kp-old {
		color: rgb(138, 138, 138);
	}
	
	.kp-message {
		display: inline-block;
		/*margin: 0 121px;*/
	}
	
	.kp-messdate {
		border: 2px solid rgb(59, 195, 194);
		font-size: 26px;
		padding: 9px 9px 9px 22px;
		line-height: 1;
		border-radius: 8px;
		display: flex;
		align-items: center;
	}
	
	.kp-traintime {
		color: rgb(59, 195, 194);
		/*margin: 9px 11px 9px 0;*/
		display: inline-block;
	}
	
	.kp-traintime>em {
		margin-right: 10px;
	}
	
	.kp-trainicon {
		display: inline-block;
		width: 48px;
		height: 40px;
		position: relative;
		vertical-align: middle;
		border-left: 2px solid rgb(59, 195, 194);
	}
	
	.kp-trainicon::before {
		content: "";
		display: inline-block;
		width: 40px;
		height: 40px;
		background: url("../../../assets/rili.png") center no-repeat;
		background-size: 40px;
		position: absolute;
		left: 8px;
		top: 0;
	}
	
	.kp-traincont {
		padding-top: 205px;
	}
	
	.trainlist {
		padding: 0 10px;
	}
	
	.trainitem {
		background: #fff;
		position: relative;
		top:0;
		left: 0;
	}
	
	.train_rob_pic {
		position: absolute;
		top:0;
		right: 0;
		width: 60px;
		height: 24px;
	}
	
	.trainitem_top {
		display: flex;
		justify-content: space-between;
		color: rgb(51, 51, 51);
		padding: 24px 21px 20px 19px;
		width: 100%;
		border-bottom: 2px dashed rgb(200, 200, 200);
	}
	
	.trainitem_top>div {
		display: flex;
		justify-content: flex-start;
	}
	
	.trainitem_start {
		width: 180px;
	}
	
	.train_city {
		font-size: 30px;
	}
	
	.train_time {
		font-size: 32px;
		margin-top: 20px;
	}
	
	.train_Startime {
		color: rgb(59, 195, 194);
	}
	
	.trainitem_end {
		width: 180px;
	}
	
	.trainitem_right {
		display: inline-block;
	}
	
	.trainitem_icon {
		font-size: 26px;
	}
	
	.train_icont {
		width: 157px;
		height: 9px;
		background: url("../../../assets/zhixiang.png") center no-repeat;
		background-size: 157px 9px;
	}
	
	.train_hao {
		margin-top: 7px;
		font-size: 26px;
	}
	
	.train_shiji {
		margin-top: 10px;
		font-size: 24px;
	}
	
	.trainitem_price {
		flex: 1;
		display: flex;
		flex-direction: column;
	}
	
	.trainprice {
		width: 100%;
		color: rgb(251, 101, 35);
		margin-top: 8px;
		text-align: right;
	}
	
	.trainspan {
		font-size: 32px;
	}
	
	.train_yj {
		font-size: 24px;
	}
	
	.train_hz {
		font-size: 23px;
	}
	
	.price_fan {
		margin-top: 8px;
	}
	
	.price_fanpr {
		display: inline-block;
		font-size: 22px;
		color: rgb(234, 51, 37);
		padding: 5px 10px;
		border: 2px solid rgb(234, 51, 37);
		border-radius: 14px;
	}
	
	.train_prifan {
		font-size: 16px;
	}
	
	.trainitem_bot {
		padding: 16px 20px;
	}
	
	.trainitem_ul {}
	
	.trainitem_ul>li {
		float: left;
		font-size: 24px;
		display: inline-block;
	}
	
	.train_em {
		color: rgb(251, 101, 35);
	}
	
	.gray {
		color: rgb(168, 168, 168);
	}
	
	.trainitem_ul {
		display: flex;
		justify-content: space-between;
		padding: 0 20px;
		box-sizing: border-box;
		width: 100%;
	}
	/*.trainitem_ul>li {
		padding-right: 20px;
	}*/
	
	.train_pno {
		color: rgb(251, 101, 35);
	}
	
	.train_pno>span {
		font-size: 24px;
	}
	
	.train_haoem {
		display: inline-block;
		width: 38px;
		height: 28px;
		background: url("../../../assets/sfz.png") center no-repeat;
		background-size: 38px 28px;
		vertical-align: -3px;
		margin-left: 7px;
	}
	
	.train_f {
		width: 100%;
		height: 98px;
	}
	
	.train_footer {
		width: 100%;
		height: 98px;
		background: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
	}
	
	.waccy-li {
		float: left;
		width: 25%;
		text-align: center;
	}
	
	.train_ficon>span {
		display: inline-block;
	}
	
	.train_shai {
		width: 36px;
		height: 38px;
		background-image: url("../../../assets/t-shaixuan.png");
		background-repeat: no-repeat;
		background-position: center;
		background-size: 36px 38px;
		margin: 15px 0 9px;
	}
	
	.waccy-li.active .train_shai {
		background-image: url("../../../assets/t-shaixuan1.png");
	}
	
	.train_chuf {
		width: 44px;
		height: 16px;
		background-image: url("../../../assets/t-chufa.png");
		background-repeat: no-repeat;
		background-position: center;
		background-size: 44px 16px;
		margin: 25px 0 21px;
	}
	
	.waccy-li.active .train_chuf {
		background-image: url("../../../assets/t-chufa1.png");
	}
	
	.train_haos {
		width: 39px;
		height: 39px;
		background-image: url("../../../assets/t-haoshi.png");
		background-repeat: no-repeat;
		background-position: center;
		background-size: 39px;
		margin: 13px 0 10px;
	}
	
	.waccy-li.active .train_haos {
		background-image: url("../../../assets/t-haoshi.png");
	}
	
	.train_you {
		width: 51px;
		height: 35px;
		background-image: url("../../../assets/t-youpiao.png");
		background-repeat: no-repeat;
		background-position: center;
		background-size: 51px 35px;
		margin: 17px 0 10px;
	}
	
	.waccy-li.active .train_you {
		background-image: url("../../../assets/t-youpiao1.png");
	}
	
	.waccy-li.active .train_fzi {
		color: rgb(59, 195, 194);
	}
	
	.kp-trainshai {
		/*width: 100%;
		height: 100%;
		position: fixed;
		left: 0;
		top: 0;
		bottom: 0;
		right: 0;*/
	}
	
	.kp-traindiv {
		position: fixed;
		left: 0;
		bottom: 66px;
		padding: 0 30px;
		z-index: 350;
	}
	
	.train_che {
		width: 690px;
		background: #fff;
		border-radius: 15px;
		overflow: hidden;
	}
	
	.train_btn {
		width: 100%;
		height: 82px;
		background: rgb(244, 245, 249);
		line-height: 82px;
		font-size: 32px;
		color: rgb(59, 195, 194);
		padding: 0 40px;
	}
	
	.train_qud {
		float: right;
	}
	
	.train_div {
		padding: 0px 59px 0;
	}
	
	.train_top {
		width: 100%;
		position: relative;
		margin-bottom: 41px;
		margin-top: 16px;
	}
	
	.train_top::before,
	.train_top::after {
		content: "";
		width: 202px;
		height: 1px;
		background: rgb(200, 200, 200);
		position: absolute;
		top: 50%;
		margin-top: -0.5px;
	}
	
	.train_top::before {
		left: 0;
	}
	
	.train_top::after {
		right: 0;
	}
	
	.train_choose {
		font-size: 26px;
		color: rgb(168, 168, 168);
	}
	
	.train_itemcar {
		width: 214px;
		float: left;
		display: inline-block;
		position: relative;
		line-height: 32px;
	}
	
	.train_itemcar:nth-child(2n-1) {
		margin-right: 140px;
		margin-bottom: 38px;
	}
	
	.train_hanzi {
		color: rgb(51, 51, 51);
		font-size: 28px;
	}
	
	.train_itemcar.active .train_hanzi {
		color: rgb(59, 195, 194);
	}
	
	.train_itemem {
		display: inline-block;
		width: 32px;
		height: 32px;
		background-image: url("../../../assets/kwx.png");
		background-repeat: no-repeat;
		background-position: center;
		background-size: 32px;
		position: absolute;
		right: 0;
		top: 50%;
		margin-top: -16px;
	}
	
	.train_itemcar.active .train_itemem {
		background-image: url("../../../assets/kxz.png");
	}
	/* 预售 */
	
	.train_presell {
		display: flex;
		font-size: 24rpx;
		color: #a8a8a8;
		justify-content: space-between;
		padding: 0 21rpx;
		width: 100%;
	}
	
	.train_presell_btn {
		font-size: 26rpx;
		color: #ea3325;
	}
	
	.train_none {
		color: rgb(168, 168, 168);
	}
	
	.train_close {
		width: 100%;
		display: flex;
		justify-content: center;
		margin-top: 20px;
	}
	
	.train_close>div {
		width: 64px;
		height: 64px;
	}
	
	.train_close>div>img {
		width: 100%;
		height: 100%;
	}
	
	.trainitem_null {
		width: 100%;
		display: flex;
		justify-content: center;
	}
	
	.trainitem_null>img {
		width: 352px;
		height: 461px;
		margin-top: 150px;
	}
	
	.trainlist_student_tip {
		background: #fffdf0;
		color: #b8845c;
		padding: 10px 20px;
		border-radius: 8px;
		line-height: 40px;
		margin: 0px 10px;	
		margin-bottom: 20px;
		box-sizing: border-box;
	}
</style>
<style>
	body {background: #F4F5F9;}
</style>
<script>
	import byIdCard from "../../../components/byIdCard"; //身份证乘车提示
	import kpmask from "../../../components/kpmask"; //蒙层
	export default {
		components: {
			byIdCard,
			kpmask
		},
		data() {
			return {
				cityMsg: {
					fromCity: "石家庄",
					toCity: "北京",
				}, //始终城市
				departureDate: "", //日期
				queryKey: "", // 提交订单页面查询余票时需要的参数
				backups: [], //所有的车辆			    
				filtrate: { // 筛选的内容
					arr: [0, 0, 0, 0, 5], // 车次类型1：高铁/城际，2：普通K/T/Z,3:动车D
					arrCopy: [0, 0, 0, 0, 5], //备份默认
					setOut: [0, 0, 0, 0, 5], // 出发时间1：0-6点，2：6-12点，3：12-18点，4：18-24点
					setOutCopy: [0, 0, 0, 0, 5], //备份默认
					arrive: [0, 0, 0, 0, 5], // 到达时间1：0-6点，2：6-12点，3：12-18点，4：18-24点
					arriveCopy: [0, 0, 0, 0, 5], //备份默认
				},
				Highspeed: false, //高铁,
				sortList: [], //符合要求数组
				trainList: [], //渲染数组
				departureDateMsg: {},
				chose: -1, //底部选项卡选中项
				departFlag: true, //发车升降序 true为升
				costTimeFlag: true, //耗时升降序 true为升
				isByIdCard: false, //高铁身份证乘车提示
				maskShowFlag: false,//蒙层显示隐藏
				advanceDate:"",//预售
				isChangTicket:false,//是否改签
				endDate:"",//可购票的最后一天的日期
				isChangeStation:false,//是否修改过车站
				isNullShow:false,//缺省图展示隐藏
				studentFlag:false,//学生票
				HCCashBackFlag:false,//返现开关
			}
		},
		created() { //创建后

		},
		mounted() { //载入后执行
			this.isChangTicket = this.$route.query.isChangTicket ? true : false;
			var trainStore = this.$store.state.train.trainStore;
			if(trainStore.advanceDate) {//预售
				this.advanceDate = trainStore.advanceDate;
				this.endDate = this.isChangTicket ? this.advanceDate.dateChange : this.advanceDate.date;
			} else {
				this.advanceBook();
			};
			(trainStore.HCCashBackFlag) ? (this.HCCashBackFlag = Boolean(Number(trainStore.HCCashBackFlag))) : this.getInsurance();//返现开关
			this.departureDate = (this.isChangTicket ? trainStore.changeMessage.departureDate : trainStore.departureDate) || this.$route.query.departureDate || new Date().format("yyyy-MM-dd"); //日期
			this.cityMsg.fromCity = this.$route.query.fromCity; //车站
			this.cityMsg.toCity = this.$route.query.toCity; //车站
			this.Highspeed = Boolean(Number(this.$route.query.Highspeed)); //是否高铁动车
			this.studentFlag = Boolean(Number(this.$route.query.studentFlag)); //是否学生票
			this.isChangeStation = this.isChangTicket ? false : Boolean(trainStore.isChangeStation);//是否有过返程查询
		},
		watch: {//监听放置
			departureDate() {
				this.departureDateMsg = this.$publicMethod.getWeek(this.departureDate);
				this.isChangeStation ? this.changeTrain() : this.getList(); //火车车次信息
				(this.chose == -1) || (this.chose = 0); //筛选
				var trainStore = JSON.parse(JSON.stringify(this.$store.state.train.trainStore));
				(this.isChangTicket) ? (trainStore.changeMessage.departureDate = this.departureDate) : (trainStore.departureDate = this.departureDate);//是否改签
				this.$store.commit('TRAINSTORE', trainStore);	
			},
			sortList() {
				this.trainList = (this.sortList.length > 10) ? this.sortList.slice(0, 10) : this.sortList;
				this.$publicMethod.onReachBottom(this.onReachBottom); //下拉加载开启
			},
		},
		methods: { //方法放置
			clickReturn() { //回退	
				this.$router.go(-1);
			},
			preday() { //前一天
				var time = this.$publicMethod.getTimeFormat(this.departureDate).getTime();
				if(new Date().getTime() > time) { //没有前一天了
					this.$toast("没有前一天了", {
					    durtaion: 200,
					    location: 'center',
					});
				} else {
					this.departureDate = this.$publicMethod.getNowFormatDateAfter(-1, this.departureDate).format("yyyy-MM-dd");
				};
			},
			nextday() { //后一天				
				var endDate = this.isChangTicket ? this.advanceDate.dateChange : this.advanceDate.date;
				if(new Date(this.departureDate.replace(/-/g, '/')).getTime() < new Date(endDate.replace(/-/g, '/')).getTime()) {
					this.departureDate = this.$publicMethod.getNowFormatDateAfter(1, this.departureDate).format("yyyy-MM-dd");
				} else { // 没有后一天了
					var time = new Date(endDate.replace(/-/g, '/'));
				    time = time.getMonth() + 1 + "月" + time.getDate() + "日";
					this.$toast('不能选择' + time + '后的日期哦', {
					    durtaion: 200,
					    location: 'center',
					});
				};
			},
			getList() { // 获取列表
				this.isNullShow = false;
				this.$loading.show();
				var param = {
					fromStation: encodeURI(this.cityMsg.fromCity),
					toStation: encodeURI(this.cityMsg.toCity),
					ticketType: this.studentFlag ? 2 : 1, // 1正常票  2学生票  默认1
					trainDate: this.departureDate.replace(/-/g, ''),
				};
				this.$http.post(this.$baseUrl.baseurl + "tctrain/train/train", param).then((res) => {
					if(res.data.Code === '0') {
						var list = res.data.Result.trains || [];
						if(list.length) {
							for(var i = 0; i < list.length; i++) {
								list[i].showNone = false; //无票
								var ticketsArr = [];
								for(var j in list[i].tickets) {
									(list[i].tickets[j].seats > 0) && (list[i].showNone = true);
									let obj = list[i].tickets[j]; //获取座位信息
									obj.seatClass = j; //添加坐席代号
									ticketsArr.push(obj);
								};
								ticketsArr.sort((a, b) => { //根据价格排序
									var a = a.lowestPrice || a.price;
									var b = b.lowestPrice || b.price;
									return b - a;
								});
								if(ticketsArr.length > 1) { //处理无座和硬座/二等座价格相同的情况
									var flag = (ticketsArr[ticketsArr.length - 1].seatName == "硬座" || ticketsArr[ticketsArr.length - 1].seatName == "二等座") && (ticketsArr[ticketsArr.length - 2].seatName == "无座");
									if(flag) {
										let obj = ticketsArr[ticketsArr.length - 2];
										ticketsArr[ticketsArr.length - 2] = ticketsArr[ticketsArr.length - 1];
										ticketsArr[ticketsArr.length - 1] = obj;
									};
								};
								list[i].ticketsArr = ticketsArr;
							};
							this.Highspeed && (this.filtrate.arr = [1, 2, 0, 0, 0]); //筛高铁
							this.queryKey = res.data.Result.queryKey || ""; //提交订单参数
							this.backups = list;
							this.isShowList = true;
							this.submit(); //筛选
							this.$publicMethod.onReachBottom(this.onReachBottom); //下拉加载开启
						} else {
							this.trainList.length = 0;
							this.$forceUpdate();
						};
						this.$loading.hide();
						this.isNullShow = true;
					} else {
						this.trainList.length = 0;
						this.$loading.hide();
						this.isNullShow = true;
						this.$toast(res.data.msg, {
						    durtaion: 200,
						    location: 'center',
						});
					};
				}).catch((err) => {
					this.$loading.hide();
					this.isNullShow = true;
					console.log(err);
				});
			},
			submit() { // 点击确定按钮 筛选
				//拷贝
				this.filtrate.arrCopy = JSON.parse(JSON.stringify(this.filtrate.arr));
				this.filtrate.setOutCopy = JSON.parse(JSON.stringify(this.filtrate.setOut));
				this.filtrate.arriveCopy = JSON.parse(JSON.stringify(this.filtrate.arrive));
				var sortObj = this.backups,
					arr = this.filtrate.arr,
					setOut = this.filtrate.setOut,
					arrive = this.filtrate.arrive,
					n = 5; //计数器
				arr = arr.join('');
				setOut = setOut.join('');
				arrive = arrive.join('');
				if(arr.indexOf(5) < 0 && arr != '00000') { // 火车类型 1-5中类型，判断arr中不包含哪种类型，将其过滤掉
					while(n) {
						if(arr.indexOf(n) < 0) {
							switch(n) {
								case 1:
									sortObj = sortObj.filter(function(e) { // 高铁城际
										return e.trainNo.indexOf('G') < 0 && e.trainNo.indexOf('C') < 0;
									});
									break;
								case 2:
									sortObj = sortObj.filter(function(e) { // 动车
										return e.trainNo.indexOf('D') < 0;
									});
									break;
								case 3:
									sortObj = sortObj.filter(function(e) { // 普通
										return e.trainNo.indexOf('Z') < 0 && e.trainNo.indexOf('T') < 0 && e.trainNo.indexOf('K') < 0;
									});
									break;
								case 4:
									sortObj = sortObj.filter(function(e) { // 其他
										return e.trainNo.indexOf('Z') > -1 || e.trainNo.indexOf('T') > -1 || e.trainNo.indexOf('K') > -1 || e.trainNo.indexOf('D') > -1 || e.trainNo.indexOf('G') > -1 || e.trainNo.indexOf('C') > -1;
									});
									break;
							};
						};
						n--;
					};
				};
				n = 5;
				if(setOut.indexOf(5) < 0 && setOut != '00000') { // 出发时间
					while(n) {
						if(setOut.indexOf(n) < 0) {
							switch(n) {
								case 1:
									sortObj = sortObj.filter(function(e) { // 6-12
										return parseInt(e.fromTime.substring(0, 2)) >= 6
									});
									break;
								case 2:
									sortObj = sortObj.filter(function(e) { // 12-18
										return parseInt(e.fromTime.substring(0, 2)) >= 12 || parseInt(e.fromTime.substring(0, 2)) < 6;
									});
									break;
								case 3:
									sortObj = sortObj.filter(function(e) { // 18-24
										return parseInt(e.fromTime.substring(0, 2)) >= 18 || parseInt(e.fromTime.substring(0, 2)) < 12;
									});
									break;
								case 4:
									sortObj = sortObj.filter(function(e) { // 不限
										return parseInt(e.fromTime.substring(0, 2)) >= 24 || parseInt(e.fromTime.substring(0, 2)) < 18;
									});
									break;
								default:
									sortObj = sortObj;
							};
						};
						n--;
					};
				};
				n = 5;
				if(arrive.indexOf(5) < 0 && arrive != '00000') { // 到达时间
					while(n) {
						if(arrive.indexOf(n) < 0) {
							switch(n) {
								case 1:
									sortObj = sortObj.filter(function(e) { // 6-12
										return parseInt(e.toTime.substring(0, 2)) >= 6
									});
									break;
								case 2:
									sortObj = sortObj.filter(function(e) { // 12-18
										return parseInt(e.toTime.substring(0, 2)) >= 12 || parseInt(e.toTime.substring(0, 2)) < 6
									});
									break;
								case 3:
									sortObj = sortObj.filter(function(e) { // 18-24
										return parseInt(e.toTime.substring(0, 2)) >= 18 || parseInt(e.toTime.substring(0, 2)) < 12
									});
									break;
								case 4:
									sortObj = sortObj.filter(function(e) { // 不限
										return parseInt(e.toTime.substring(0, 2)) >= 24 || parseInt(e.toTime.substring(0, 2)) < 18
									});
									break;
								default:
									sortObj = sortObj;
							};
						};
						n--;
					};
				};
				this.maskShowFlag = false;
				this.sortList = sortObj;
			},
			onReachBottom() { //下拉加载
				let current = this.trainList.length;
				let all = this.sortList.length;
				(current < all) ? (this.trainList.push(...this.sortList.slice(current, current + 10))) : this.$publicMethod.onReachBottom(false);
			},
			changeTrain(flag) { //返程查询
				var fromCity = this.cityMsg.fromCity;
				this.cityMsg.fromCity = this.cityMsg.toCity;
				this.cityMsg.toCity = fromCity;
				flag && (this.isChangeStation = !this.isChangeStation);
				this.getList();
			},
			depart() { // 点击发车
//				var sortObj = this.backups.sort(this.getSort("fromTime", !this.departFlag));
				var sortObj = this.sortList.sort(this.getSort("fromTime", !this.departFlag));
				this.chose = 1;
				this.departFlag = !this.departFlag;
				this.sortList = sortObj;
			},
			costTime() { // 点击耗时
//				var sortObj = this.backups.sort(this.getSort("runTimeSpan", !this.costTimeFlag));
				var sortObj = this.sortList.sort(this.getSort("runTimeSpan", !this.costTimeFlag));
				this.chose = 2;
				this.costTimeFlag = !this.costTimeFlag;
				this.sortList = sortObj;
			},
			have() { // 点击有票优先
//				var sortObj = this.backups.sort(function(a, b) {
				var sortObj = this.sortList.sort(function(a, b) {
					a.num = 0;
					b.num = 0;
					for(var j in a.tickets) {
						a.num += parseInt(a.tickets[j].seats);
					};
					for(var j in b.tickets) {
						b.num += parseInt(b.tickets[j].seats);
					};
					return b.num - a.num
				});
				this.chose = 3;
				this.sortList = sortObj;
			},
			getSort(property, flag) { //排序 true 为降序 false为升序
				return function(a, b) {
					var value1, value2;
					if(property == 'fromTime') { //如果是发车
						value1 = parseInt(a[property].substring(0, 2)) * 60 + parseInt(a[property].substring(3, 5));
						value2 = parseInt(b[property].substring(0, 2)) * 60 + parseInt(b[property].substring(3, 5));
					} else {
						value1 = Number(a[property]);
						value2 = Number(b[property]);
						//						console.log(value1,value2);
					};
					var value = flag ? value2 - value1 : value1 - value2;
					return value;
				};
			},
			maskClick() { //筛选蒙层
				this.maskShowFlag = false;
				this.filtrate.arr = this.filtrate.arrCopy;
				this.filtrate.setOut = this.filtrate.setOutCopy;
				this.filtrate.arrive = this.filtrate.arriveCopy;
				this.$forceUpdate();
			},
			idCardClick() { //身份证标识
				this.isByIdCard = false;
			},
			filtRate() { //筛选
				this.chose = 0;
				this.maskShowFlag = true;
			},
			filtRateClick(index, types) {
				(types == "car") && (this.Highspeed = false);
				var arr = (types == "car") ? (this.filtrate.arr) : (types == "fromTime") ? (this.filtrate.setOut) : (types == "toTime") && this.filtrate.arrive;
				index = parseInt(index);
				if(index == 4) {
					(arr[4]) || (arr = [0, 0, 0, 0, index + 1]); //已是不限不支持反选
				} else {
					arr[index] ? (arr[index] = 0) : (arr[index] = index + 1);
					(arr[0] || arr[1] || arr[2] || arr[3]) ? (arr[4] = 0) : (arr[4] = 5); //全部取消选不限
				};
				(types == "car") ? (this.filtrate.arr = arr) : (types == "fromTime") ? (this.filtrate.setOut = arr) : (types == "toTime") && (this.filtrate.arrive = arr);
				this.$forceUpdate();
			},
			trainDetails(item){
				this.$router.push({
					name: 'trainSeat',
					query: {
						trainNo:item.trainNo || item.trainNum,
						departureDate:this.departureDate,
						isChangTicket: this.isChangTicket ? 1 : 0,
						fromStation:item.fromStation || item.fromCity,
						toStation:item.toStation || item.toCity,
						studentFlag:Number(this.studentFlag)
					},
				});
			},
			advanceBook() { //预售查询
				this.$http.post(this.$baseUrl.baseurl + "tctrain/train/trainAdvanceTime", {}).then((res) => {
					var data = res.data.Result;
					var dayNum = Number(data.trainAdvanceDays) + Number(data.trainQPvanceDays);
					//替换@
					data.trainGQTips = data.trainGQTips.replace(/@/g, data.trainAdvanceDays);
					data.trainTips = data.trainTips.replace(/@/g, data.trainQPvanceDays);
					//存全局
					var trainStore = JSON.parse(JSON.stringify(this.$store.state.train.trainStore));
					trainStore.advanceDate = data;
					trainStore.advanceDate.dayNum = dayNum;
					trainStore.advanceDate.date = data.trainQPAdvanceTime;
					trainStore.advanceDate.dateChange = data.advanceTime;
					this.$store.commit('TRAINSTORE', trainStore);
					this.advanceDate = this.$store.state.train.trainStore.advanceDate;
					this.endDate = this.isChangTicket ? this.advanceDate.dateChange : this.advanceDate.date;
				}).catch((err) => {
					console.log(err);
				});
			},
			getInsurance() { //获取保险开关
				this.$http.post(this.$baseUrl.baseurl + "kpcx/switch/getAllSwitch", {
					"switch": "All",
				}).then((res) => {
					var trainStore = JSON.parse(JSON.stringify(this.$store.state.train.trainStore));
					trainStore.insuranceFlag = res.data.Result.activityInfo.Insure; //存到全局(0关1开)
					trainStore.HCCashBackFlag = res.data.Result.activityInfo.HCCashBack; //返现
					this.HCCashBackFlag = Boolean(Number(res.data.Result.activityInfo.HCCashBack));
					this.$store.commit('TRAINSTORE', trainStore); 
				}).catch((err) => {
					console.log(err);
				});
			},
		},
		filters: {
			runTime(runTime) {
				return(Math.floor(runTime / 60) > 0) ? (Math.floor(runTime / 60) + '小时' + (runTime % 60) + '分钟') : (runTime + "分钟");
			},
			returnMoney(price){//返现
			    //该公式在价格为1.4时计算基本为0但由于保留一位小数所以在计算得0.09时也展示为0，因此判断为3.6时展示为0.1;
			    var money = (price / (20 + price / 50) * (Math.log(price) / Math.log(10))).toFixed(3);
			    money = money.substring(0,money.length-2);
			    (money.substring(money.length - 1) == 0) && (money = money.substring(0, money.length - 1));
			    money = + money;
			    (money > 30) && (money = 30); 
			    return money;
		  	},
		},
		beforeRouteLeave(to, from, next) {
			var trainStore = JSON.parse(JSON.stringify(this.$store.state.train.trainStore));
			trainStore.isChangeStation = (to.name == "train") ? null : this.isChangeStation;
			this.$store.commit('TRAINSTORE', trainStore);
			next();
		},
	}
</script>